﻿using System;
using System.Collections.Generic;
using System.Text;
using TileGert;

namespace TestApp.Tests
{
  class RectangleIntersection : TestGame
  {
    private GertRectangle _rect1 = new GertRectangle(400, 300, 450, 500);
    private GertRectangle _rect2 = new GertRectangle(200, 200, 350, 350);
    private GertRectangle _intersect = null;

    protected override void Update(float timestep)
    {
      int step = 100;
      Input.Update();
      if (Input.Keyboard.KeyIsPressed(GertKeys.LeftArrow))
        _rect1.LeftTop.X -= step * timestep;
      if (Input.Keyboard.KeyIsPressed(GertKeys.RightArrow))
        _rect1.LeftTop.X += step * timestep;
      if (Input.Keyboard.KeyIsPressed(GertKeys.UpArrow))
        _rect1.LeftTop.Y -= step * timestep;
      if (Input.Keyboard.KeyIsPressed(GertKeys.DownArrow))
        _rect1.LeftTop.Y += step * timestep;

      if (_rect1.Intersects(_rect2))
        _intersect = _rect1.GetIntersection(_rect2);
      else
        _intersect = null;
    }

    protected override void Render()
    {
      Renderer.Clear(GertColor.Navy);
      Renderer.Begin();

      Renderer.ForegroundColor = GertColor.White;
      Renderer.DrawRectangle(_rect1);
      Renderer.DrawRectangle(_rect2);

      if (_intersect != null)
      {
        Renderer.ForegroundColor = GertColor.Red;
        Renderer.DrawRectangle(_intersect);
      }

      Renderer.End();
    }

  }
}
